-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve handling of rustdoc lints when used with raw doc fragments. #136400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improve handling of rustdoc lints when used with raw doc fragments. #136400
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a9a435b
to
c6d7696
Compare
@fmease what module do you want me to move |
@fmease reminder to look at this. |
@fmease it's been a week, are you going to get to this, or should I reroll reviewers? |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…1, r=<try> Improve handling of rustdoc lints when used with raw doc fragments. 1. `rustdoc::bare_urls` no longer outputs incoherent suggestions if `source_span_for_markdown_range` returns None, instead outputting no suggestion 2. `source_span_for_markdown_range` has one more heuristic, so it will return `None` less often. 3. add ui test to make sure we don't emit nonsense suggestions. fixes rust-lang#135851
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (75eefd1): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (secondary -4.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 776.227s -> 775.389s (-0.11%) |
@fmease all recommended changes added |
let mut match_data = None; | ||
let pat = &markdown[md_range.clone()]; | ||
// this heirustic doesn't make sense with a zero-sized range. | ||
if pat.len() == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if pat.len() == 0 { | |
if pat.is_empty() { |
@@ -528,6 +536,38 @@ pub fn source_span_for_markdown_range( | |||
let is_all_sugared_doc = fragments.iter().all(|frag| frag.kind == DocFragmentKind::SugaredDoc); | |||
|
|||
if !is_all_sugared_doc { | |||
// this case ignores the markdown outside of the range so that it can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// this case ignores the markdown outside of the range so that it can | |
// This case ignores the markdown outside of the range so that it can |
// fragments. | ||
let mut match_data = None; | ||
let pat = &markdown[md_range.clone()]; | ||
// this heirustic doesn't make sense with a zero-sized range. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// this heirustic doesn't make sense with a zero-sized range. | |
// This heuristic doesn't make sense with a zero-sized range. |
pub fn source_span_for_markdown_range( | ||
tcx: TyCtxt<'_>, | ||
markdown: &str, | ||
md_range: &Range<usize>, | ||
fragments: &[DocFragment], | ||
) -> Option<Span> { | ||
let span_to_snippet = |span| tcx.sess.source_map().span_to_snippet(span); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: just do let map = tcx.sess.source_map();
and change call sites to map.snap_to_snippet(…)
, it's hardly longer
// if there is either a match in a previous fragment, | ||
// or multiple matches in this fragment, | ||
// there is ambiguity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if there is either a match in a previous fragment, | |
// or multiple matches in this fragment, | |
// there is ambiguity. | |
// If there is either a match in a previous fragment, or | |
// multiple matches in this fragment, there is ambiguity. |
} | ||
} | ||
if let Some((i, match_start)) = match_data { | ||
use rustc_span::BytePos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this import either at the beginning of the function or at the top of the file.
if match_data.is_none() && !snippet[match_start + 1..].contains(pat) { | ||
match_data = Some((i, match_start)); | ||
} else { | ||
// heirustic produced ambiguity, return nothing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// heirustic produced ambiguity, return nothing. | |
// Heuristic produced ambiguity, return nothing. |
let mut sp = fragments[i].span; | ||
sp = sp.with_lo(sp.lo() + BytePos(match_start as u32)); | ||
sp = sp.with_hi(sp.lo() + BytePos((md_range.end - md_range.start) as u32)); | ||
return Some(sp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut sp = fragments[i].span; | |
sp = sp.with_lo(sp.lo() + BytePos(match_start as u32)); | |
sp = sp.with_hi(sp.lo() + BytePos((md_range.end - md_range.start) as u32)); | |
return Some(sp); | |
return Some(fragments[i].span.with_lo(sp.lo() + BytePos(match_start as u32)).with_hi(sp.lo() + BytePos((md_range.end - md_range.start) as u32))); |
// the fallback of using the attribute span is suitable for | ||
// highlighting where the error is, but not for placing the < and > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// the fallback of using the attribute span is suitable for | |
// highlighting where the error is, but not for placing the < and > | |
// The fallback of using the attribute span is suitable for | |
// highlighting where the error is, but not for placing the `<` and `>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code logic is good, just some nits and then it's good to go.
rustdoc::bare_urls
no longer outputs incoherent suggestions ifsource_span_for_markdown_range
returns None, instead outputting no suggestionsource_span_for_markdown_range
has one more heuristic, so it will returnNone
less often.fixes #135851